package bancosys.tec.security.impl.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Index;

import org.hibernate.annotations.Filter;
import org.hibernate.annotations.Filters;
import org.hibernate.annotations.ForeignKey;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.AuthPersistableBusinessObject;

/**
 * Representa o id de uma entidade de credencial Chinese Wall.
 * 
 * @author piercio Created 08.04.2008
 */
@Entity
@Table(name = "CREDENTIAL_ENTITY_ID")
@Alias("CREENI")
@SequenceGenerator(name = "SEQ_CREENI", sequenceName = "SEQ_CREENI")
@Index(suffix = "JT_2", columns = { "COD_CREDENTIAL", "COD_ENTITY" })
@Filters({ @Filter(name = "authFilter", condition = "auth = :auth") })
@Documentation("ARMAZENA OS IDS DAS CREDENCIAIS UTILIZADAS NO CHINESE WALL.")
public class ChineseWallEntityId extends AuthPersistableBusinessObject {

    private Long id;

    private Long entityId;

    private ChineseWallCredential credential;

    /**
     * @return ID.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ_CREENI")
    @Column(name = "COD_CRED_ENTITY", nullable = false)
    @Documentation("CODIGO DA CREDENCIAL DA. ENTIDADE")
    public Long getId() {
        return this.id;
    }

    /**
     * Define o ID.
     * 
     * @param id o ID.
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Devolve o id de entidade chinese wall.
     * 
     * @return o id de entidade chinese wall.
     */
    @Column(name = "COD_ENTITY", nullable = false)
    @Index(suffix = "JT_1")
    @Documentation("CODIGO DA ENTIDADE PERMITIDOS PARA A CREDENCIAL.")
    public Long getEntityId() {
        return this.entityId;
    }

    /**
     * Define o id de entidade chinese wall.
     * 
     * @param entityId o id de entidade chinese wall.
     */
    public void setEntityId(Long entityId) {
        this.entityId = entityId;
    }

    /**
     * Devolve a credencial chinese wall.
     * 
     * @return a credencial chinese wall.
     */
    @ManyToOne
    @Index(suffix = "JT_0")
    @JoinColumn(name = "COD_CREDENTIAL")
    @ForeignKey(name = "FK_CREDEN_CREENI")
    @Documentation("CODIGO DA CREDENCIAL.")
    public ChineseWallCredential getCredential() {
        return this.credential;
    }

    /**
     * Define a credencial chinese wall.
     * 
     * @param credential a credencial chinese wall.
     */
    public void setCredential(ChineseWallCredential credential) {
        this.credential = credential;
    }

    /**
     * Devolve a representação desse objeto.
     * 
     * @return a representação desse objeto.
     */
    @Override
    public String toString() {
        return this.entityId.toString();
    }
}
